﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Program05
{
    class Program
    {
        static void Main(string[] args)
        {
            while (Console.ReadLine() != "1")
            {
                Console.WriteLine("请输入性别(男/女)：");
                string sex = Console.ReadLine();
                while(!(sex=="男" || sex == "女"))
                {
                    Console.WriteLine("您的输入的性别不合法，请重新输入");
                    sex = Console.ReadLine();
                }
                Console.WriteLine("请输入身高(cm)：");
                int heigth = Convert.ToInt32(Console.ReadLine());
                while(!(heigth>0))
                {
                    Console.WriteLine("您的输入的身高不合法，请重新输入");
                    heigth = Convert.ToInt32(Console.ReadLine());
                }

                Console.WriteLine("请输入体重(kg)：");
                int weith = Convert.ToInt32(Console.ReadLine());
                while (!(weith > 0 ))
                {
                    Console.WriteLine("您的输入的体重不合法，请重新输入");
                    heigth = Convert.ToInt32(Console.ReadLine());
                }
                Program pro = new Program();

                Console.WriteLine("您的健康状况：" + pro.Health(sex, heigth, weith));
            }
            //Console.ReadLine();

        }
        /// <summary>
        /// 根据输入的信息判断健康状况
        /// </summary>
        /// <param name="sex">性别</param>
        /// <param name="hei">身高</param>
        /// <param name="wei">体重</param>
        /// <returns></returns>
        public string Health(string sex,int hei,int wei)
        {
            string res = ""; //返回结果
            double weigth; //标准体重

            if (sex == "男")
            {
                weigth = (hei - 80) * 0.7;

                res = Judge(wei, weigth);
            }
            if (sex == "女")
            {
                weigth = (hei - 70) * 0.6;

                res = Judge(wei, weigth);
            }
            return res;
        }

        /// <summary>
        /// 判断不同的健康状况
        /// </summary>
        /// <param name="wei">输入的体重</param>
        /// <param name="weigth">公式计算后标准体重</param>
        /// <returns></returns>
        private static string Judge(int wei, double weigth)
        {
            string res;
            //正常体重
            double wei1 = Convert.ToDouble(weigth * 0.1);
            //过重或过轻
            double wei2 = Convert.ToDouble(weigth * 0.2);

            if (wei < (weigth + wei1) & wei > (weigth - wei1))
            {
                res = "正常体重";
            }
            else if (wei >= (weigth + wei1) & wei <= (weigth + wei2))
            {
                res = "体重过重";
            }
            else if (wei <= (weigth - wei1) & wei > (weigth - wei2))
            {
                res = "体重过轻";
            }
            else if (wei > (weigth + wei2))
            {
                res = "肥胖";
            }
            else if (wei < (weigth - wei2))
            {
                res = "体重不足";
            }
            else
            {
                res = "请重新输入正确的身高体重";
            }

            return res;
        }
    }
}
